 <template>
  <div class="changereceipt">
    <van-nav-bar
      title="修改收货地址信息"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-address-edit
      :area-list="areaList"
      :addressInfo="addressInfo"
      show-set-default
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
     
    />
  </div>
</template>

<script>
import { Toast } from "vant";
import areaList from "../../util/area";
import { getreceiptoneapi,updatareceiptapi } from "../../api/receipt";
export default {
  data() {
    return {
      areaList,
      searchResult: [],
      addressInfo: {
        name: "",
        tel: "",
        addressDetail: "",
        idDefault: false,
        areaCode: "", //北京市
      },
    };
  },
  computed: {},
  watch: {},

  methods: {
    //数据回显
    show() {
      const mobile = localStorage.getItem("mobile") || "";
      const idDefault = localStorage.getItem("idDefault") || "";
      const receiver = localStorage.getItem("receiver") || "";
      const regions = localStorage.getItem("regions") || "";
      const address = localStorage.getItem("address") || "";
      console.log(mobile, idDefault, receiver, regions, address);
      console.log(receiver);
      console.log(regions.split("/"));
      this.addressInfo.name = receiver;
      this.addressInfo.tel = mobile;
      this.addressInfo.addressDetail = address;
      this.addressInfo.isDefault = idDefault;
      this.addressInfo.areaCode = "110000"; //设置省ID
      this.addressInfo.areaCode = "110100"; //设置市ID
      this.addressInfo.areaCode = "110102"; //设置区ID
    },
    //返回上一步
    onClickLeft() {
      Toast("返回");
      this.$router.go(-1);
    },
    // 提交修改信息
    async onSave(ass) {
      console.log(ass);
      console.log(ass.name);
       const obj={receiver:ass.name,mobile:ass.tel,address:ass.addressDetail,idDefault:ass.isDefault,regions:"北京市/北京市/西城区"}
        console.log(obj);
         const id = this.$route.params.id;
      const result =await updatareceiptapi(id,obj);
      console.log(result);
      // Toast("保存修改信息");
    },
    // 获取地址信息
    async getreceiptone(id) {
      const result = await getreceiptoneapi(id);
      console.log(result);
      //   this.idDefault=idDefault
    },
   
  },
  created() {
    this.show();
    //查询
    const id = this.$route.params.id;
    console.log(id);
    this.getreceiptone(id);
  },
  mounted() {
    this.addressInfo.province = 110000;
  },
  components: {},
};
</script>
<style scoped></style>
 